package com.ticket.sass.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ticket.sass.admin.mapper.PriceSchemeMemberPriceMapper;
import com.ticket.sass.admin.service.BaseService;
import com.ticket.sass.common.entity.tenant.PriceSchemeMemberPriceEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ywb
 * @since 2024-03-20
 */
@Service
public class PriceSchemeMemberPriceServiceImpl extends ServiceImpl<PriceSchemeMemberPriceMapper, PriceSchemeMemberPriceEntity> implements BaseService<PriceSchemeMemberPriceEntity> {
    public Map<Long, List<PriceSchemeMemberPriceEntity>> listMemberPricesByPriceSchemeIds(List<Long> priceSchemeIds) {
        if (priceSchemeIds == null || priceSchemeIds.isEmpty()) {
            return new HashMap<>();
        }
        
        // 将价格方案ID列表转换为逗号分隔的字符串
        String priceSchemeIdsString = String.join(",", priceSchemeIds.stream().map(String::valueOf).collect(Collectors.toList()));
        
        // 调用Mapper方法查询价格方案对应的会员价格
        List<PriceSchemeMemberPriceEntity> prices = this.baseMapper.listByPriceSchemeIds(priceSchemeIdsString);
        
        // 构建结果映射
        Map<Long, List<PriceSchemeMemberPriceEntity>> resultMap = new HashMap<>();
        for (PriceSchemeMemberPriceEntity price : prices) {
            Long priceSchemeId = price.getPriceSchemeId(); // 假设PriceSchemeMemberPriceEntity有一个方法可以获取价格方案ID
            if (!resultMap.containsKey(priceSchemeId)) {
                resultMap.put(priceSchemeId, new ArrayList<>());
            }
            resultMap.get(priceSchemeId).add(price);
        }
        
        return resultMap;
    }
}
